package utils

import "golang.org/x/crypto/bcrypt"

// password.go
// 实现密码相关功能

// HashPassword 函数如其名
func HashPassword(password string) (string, error) {
    hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
    return string(hashedPassword), err
}

// CheckPassword 校验密码
// @param password: 要校验的密码
// @param hashedPwd: 已哈希的密码
func CheckPassword(password, hashedPwd string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashedPwd), []byte(password))
	return err == nil
}